//
// Created by yangchao on 2022/7/13.
// 27. 移除元素: https://leetcode.cn/problems/remove-element/
//

#include <vector>
using namespace std;

class RemoveElement {
public:
    int removeElement(vector<int>& nums, int val) {
        /* 快指针：寻找新数组的元素 ，新数组就是不含有目标元素的数组
           慢指针：指向更新 新数组下标的位置*/
        int slowIndex = 0;
        for (int fastIndex = 0; fastIndex < nums.size(); ++fastIndex) {
            if (nums[fastIndex] != val) {
                nums[slowIndex++] = nums[fastIndex];
            }
        }
        return slowIndex;
    }
};

